package com.itelecom.oss.mobile.dao;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import com.itelecom.oss.Constants;
import com.itelecom.oss.mobile.domains.DeviceForMobile;

public class ParseDomain {

	public static void parseUser(XmlPullParser parser, Boolean result)
			throws XmlPullParserException, IOException {
		
		
		int type;
		String name;
		final int depth = parser.getDepth();

		while (((type = parser.next()) != XmlPullParser.END_TAG || parser
				.getDepth() > depth)
				&& type != XmlPullParser.END_DOCUMENT) {
			if (type != XmlPullParser.START_TAG) {
				continue;
			}

			name = parser.getName();
			if (Constants.RESPONSE_TAG_USER.equals(name)) {
				String t = parser.getAttributeValue(null,
						Constants.RESPONSE_ATTR_LOGIN);
				if (t != null) {
					result = true;
					
				}

			}
		}
		result = false;
	
	}

	public static void parseDevices(XmlPullParser parser,
			List<DeviceForMobile> devices) throws XmlPullParserException, IOException {
//		int type;
//		String name;
//		int depth = parser.getDepth();
//
//		while (((type = parser.next()) != XmlPullParser.END_TAG || parser
//				.getDepth() > depth)
//				&& type != XmlPullParser.END_DOCUMENT) {
//			if (type != XmlPullParser.START_TAG) {
//				continue;
//			}
//
//			name = parser.getName();
//			if (Constants.RESPONSE_TAG_DEVICES.equals(name)) {
//
//				devices = new ArrayList<DeviceForMobile>();
//			} else if (Constants.RESPONSE_TAG_DEVICE.equals(name)) {
//				DeviceForMobile device = new DeviceForMobile();
//				device.setId(parser.getAttributeValue(null,
//						Constants.RESPONSE_ATTR_DEVCIE_ID));
//				device.setLocation(parser.getAttributeValue(null,
//						Constants.RESPONSE_ATTR_DEVCIE_LOCATION));
//				device.setState(parser.getAttributeValue(null,
//						Constants.RESPONSE_ATTR_DEVCIE_STATE));
//				device.setModel(parser.getAttributeValue(null,
//						Constants.RESPONSE_ATTR_DEVCIE_MODEL));
//				device.setName(parser.getAttributeValue(null,
//						Constants.RESPONSE_ATTR_DEVCIE_NAME));
//				device.setDescription(parser.getAttributeValue(null,
//						Constants.RESPONSE_ATTR_DEVCIE_DESCRIPTION));
//
//				// if (parseFormat == null) {
//				// parseFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//				// outputFormat = new SimpleDateFormat("MMMM d, yyyy");
//				// }
//				// try {
//				// photo.mDate =
//				// outputFormat.format(parseFormat.parse(photo.mDate));
//				// } catch (ParseException e) {
//				// android.util.Log.w(LOG_TAG, "Could not parse photo date", e);
//				// }
//
//				devices.add(device);
//			}
//		}
	}

	public static String DeviceToXml(DeviceForMobile device) {
		String st = "";
		st = st + "<DeviceForMobile> " + "<id> " + device.getId() + "</id> "
				+ "<location>" + device.getLocation() + "</location>"
				+ "<state>" + device.getState() + "</state>" + "<model>"
				+ device.getModel() + "</model>" + "<name>" + device.getName()
				+ "</name>" + "<description>" + device.getDescription()
				+ "</description>" + "</DeviceForMobile>";
		return st;
	}
}